package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Salary;
import com.ruoyi.system.service.ISalaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 薪资Controller
 * 
 * @author ruoyi
 * @date 2023-12-15
 */
@Controller
@RequestMapping("/system/salary")
public class SalaryController extends BaseController
{
    private String prefix = "system/salary";

    @Autowired
    private ISalaryService salaryService;

    @RequiresPermissions("system:salary:view")
    @GetMapping()
    public String salary()
    {
        return prefix + "/salary";
    }

    /**
     * 查询薪资列表
     */
    @RequiresPermissions("system:salary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Salary salary)
    {
        startPage();
        List<Salary> list = salaryService.selectSalaryList(salary);
        return getDataTable(list);
    }

    /**
     * 导出薪资列表
     */
    @RequiresPermissions("system:salary:export")
    @Log(title = "薪资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Salary salary)
    {
        List<Salary> list = salaryService.selectSalaryList(salary);
        ExcelUtil<Salary> util = new ExcelUtil<Salary>(Salary.class);
        return util.exportExcel(list, "薪资数据");
    }

    /**
     * 新增薪资
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存薪资
     */
    @RequiresPermissions("system:salary:add")
    @Log(title = "薪资", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Salary salary)
    {
        return toAjax(salaryService.insertSalary(salary));
    }

    /**
     * 修改薪资
     */
    @RequiresPermissions("system:salary:edit")
    @GetMapping("/edit/{salaryID}")
    public String edit(@PathVariable("salaryID") Long salaryID, ModelMap mmap)
    {
        Salary salary = salaryService.selectSalaryBySalaryID(salaryID);
        mmap.put("salary", salary);
        return prefix + "/edit";
    }

    /**
     * 修改保存薪资
     */
    @RequiresPermissions("system:salary:edit")
    @Log(title = "薪资", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Salary salary)
    {
        return toAjax(salaryService.updateSalary(salary));
    }

    /**
     * 删除薪资
     */
    @RequiresPermissions("system:salary:remove")
    @Log(title = "薪资", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(salaryService.deleteSalaryBySalaryIDs(ids));
    }
}
